<!DOCTYPE html><html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
<meta charset="utf-8">
<title>phpDocumentor » \ActiveRecord\JsonSerializer</title>
<meta name="author" content="Mike van Riel">
<meta name="description" content="">
<link href="../css/template.css" rel="stylesheet" media="all">
<script src="../js/jquery-1.7.1.min.js" type="text/javascript"></script><script src="../js/jquery-ui-1.8.2.custom.min.js" type="text/javascript"></script><script src="../js/jquery.mousewheel.min.js" type="text/javascript"></script><script src="../js/bootstrap.js" type="text/javascript"></script><script src="../js/template.js" type="text/javascript"></script><script src="../js/prettify/prettify.min.js" type="text/javascript"></script><link rel="shortcut icon" href="../img/favicon.ico">
<link rel="apple-touch-icon" href="../img/apple-touch-icon.png">
<link rel="apple-touch-icon" sizes="72x72" href="../img/apple-touch-icon-72x72.png">
<link rel="apple-touch-icon" sizes="114x114" href="../img/apple-touch-icon-114x114.png">
</head>
<body>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner"><div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></a><a class="brand" href="../index.html">phpDocumentor</a><div class="nav-collapse"><ul class="nav">
<li class="dropdown">
<a href="#api" class="dropdown-toggle" data-toggle="dropdown">
                                    API Documentation <b class="caret"></b></a><ul class="dropdown-menu">
<li><a>Packages</a></li>
<li><a href="../packages/ActiveRecord.html"><i class="icon-folder-open"></i> ActiveRecord</a></li>
<li><a href="../packages/Default.html"><i class="icon-folder-open"></i> Default</a></li>
</ul>
</li>
<li class="dropdown" id="charts-menu">
<a href="#charts" class="dropdown-toggle" data-toggle="dropdown">
                                    Charts <b class="caret"></b></a><ul class="dropdown-menu"><li><a href="../graph_class.html"><i class="icon-list-alt"></i> Class hierarchy diagram</a></li></ul>
</li>
<li class="dropdown" id="reports-menu">
<a href="#reports" class="dropdown-toggle" data-toggle="dropdown">
                                    Reports <b class="caret"></b></a><ul class="dropdown-menu">
<li><a href="../errors.html"><i class="icon-remove-sign"></i> Errors 
                <span class="label label-info">310</span></a></li>
<li><a href="../markers.html"><i class="icon-map-marker"></i> Markers 
                <ul><li>todo 
                <span class="label label-info">5</span>
</li></ul></a></li>
<li><a href="../deprecated.html"><i class="icon-stop"></i> Deprecated elements 
                <span class="label label-info">3</span></a></li>
</ul>
</li>
</ul></div>
</div></div>
<div class="go_to_top"><a href="#___" style="color: inherit">Back to top  <i class="icon-upload icon-white"></i></a></div>
</div>
<div id="___" class="container">
<noscript><div class="alert alert-warning">
                            Javascript is disabled; several features are only available
                            if Javascript is enabled.
                        </div></noscript>
<div class="row">
<div class="span4">
<span class="btn-group visibility" data-toggle="buttons-checkbox"><button class="btn public active" title="Show public elements">Public</button><button class="btn protected" title="Show protected elements">Protected</button><button class="btn private" title="Show private elements">Private</button><button class="btn inherited active" title="Show inherited elements">Inherited</button></span><div class="btn-group view pull-right" data-toggle="buttons-radio">
<button class="btn details" title="Show descriptions and method names"><i class="icon-list"></i></button><button class="btn simple" title="Show only method names"><i class="icon-align-justify"></i></button>
</div>
<ul class="side-nav nav nav-list">
<li class="nav-header">
<i class="icon-custom icon-method"></i> Methods
                    <ul>
<li class="method public inherited"><a href="#method___construct" title="__construct :: Constructs a {@link Serialization} object."><span class="description">Constructs a {@link Serialization} object.</span><pre>__construct()</pre></a></li>
<li class="method public inherited"><a href="#method___toString" title="__toString :: Returns the serialized object as a string."><span class="description">Returns the serialized object as a string.</span><pre>__toString()</pre></a></li>
<li class="method public inherited"><a href="#method_to_a" title="to_a :: Returns the attributes array."><span class="description">Returns the attributes array.</span><pre>to_a()</pre></a></li>
<li class="method public "><a href="#method_to_s" title="to_s :: Performs the serialization."><span class="description">Performs the serialization.</span><pre>to_s()</pre></a></li>
</ul>
</li>
<li class="nav-header protected">» Protected
                    <ul><li class="method protected inherited"><a href="#method_options_to_a" title="options_to_a :: "><span class="description">options_to_a()
        </span><pre>options_to_a()</pre></a></li></ul>
</li>
<li class="nav-header private">» Private
                    <ul>
<li class="method private inherited"><a href="#method_check_except" title="check_except :: "><span class="description">check_except()
        </span><pre>check_except()</pre></a></li>
<li class="method private inherited"><a href="#method_check_include" title="check_include :: "><span class="description">check_include()
        </span><pre>check_include()</pre></a></li>
<li class="method private inherited"><a href="#method_check_methods" title="check_methods :: "><span class="description">check_methods()
        </span><pre>check_methods()</pre></a></li>
<li class="method private inherited"><a href="#method_check_only" title="check_only :: "><span class="description">check_only()
        </span><pre>check_only()</pre></a></li>
<li class="method private inherited"><a href="#method_check_only_method" title="check_only_method :: "><span class="description">check_only_method()
        </span><pre>check_only_method()</pre></a></li>
<li class="method private inherited"><a href="#method_parse_options" title="parse_options :: "><span class="description">parse_options()
        </span><pre>parse_options()</pre></a></li>
</ul>
</li>
<li class="nav-header">
<i class="icon-custom icon-property"></i> Properties
                    <ul>
<li class="property public inherited"><a href="#property_DATETIME_FORMAT" title="$DATETIME_FORMAT :: The default format to serialize DateTime objects to."><span class="description"></span><pre>$DATETIME_FORMAT</pre></a></li>
<li class="property public "><a href="#property_include_root" title="$include_root :: "><span class="description"></span><pre>$include_root</pre></a></li>
</ul>
</li>
<li class="nav-header protected">» Protected
                    <ul>
<li class="property protected inherited"><a href="#property_attributes" title="$attributes :: "><span class="description"></span><pre>$attributes</pre></a></li>
<li class="property protected inherited"><a href="#property_includes_with_class_name_element" title="$includes_with_class_name_element :: Set this to true if the serializer needs to create a nested array keyed
on the name of the included classes such as for xml serialization."><span class="description"></span><pre>$includes_with_class_name_element</pre></a></li>
<li class="property protected inherited"><a href="#property_model" title="$model :: "><span class="description"></span><pre>$model</pre></a></li>
<li class="property protected inherited"><a href="#property_options" title="$options :: "><span class="description"></span><pre>$options</pre></a></li>
</ul>
</li>
</ul>
</div>
<div class="span8">
<a id="\ActiveRecord\JsonSerializer"></a><ul class="breadcrumb">
<li>
<a href="../index.html"><i class="icon-custom icon-class"></i></a><span class="divider">\</span>
</li>
<li><a href="../namespaces/ActiveRecord.html">ActiveRecord</a></li>
<li class="active">
<span class="divider">\</span><a href="../classes/ActiveRecord.JsonSerializer.html">JsonSerializer</a>
</li>
</ul>
<div class="element class">
<p class="short_description">JSON serializer.</p>
<div class="details">
<div class="long_description"><p>All serializers support the following options:</p>

<ul>
<li><b>only:</b> a string or array of attributes to be included.</li>
<li><b>except:</b> a string or array of attributes to be excluded.</li>
<li><b>methods:</b> a string or array of methods to invoke. The method's name will be used as a key for the final attributes array
along with the method's returned value</li>
<li><b>include:</b> a string or array of associated models to include in the final serialized product.</li>
<li><b>only_method:</b> a method that's called and only the resulting array is serialized
<li><b>skip_instruct:</b> set to true to skip the <?xml ...?> declaration.</li>
</ul>

<p>Example usage:</p>

<pre><code># include the attributes id and name
# run $model->encoded_description() and include its return value
# include the comments association
# include posts association with its own options (nested)
$model->to_json(array(
  'only' => array('id','name', 'encoded_description'),
  'methods' => array('encoded_description'),
  'include' => array('comments', 'posts' => array('only' => 'id'))
));

# except the password field from being included
$model->to_xml(array('except' => 'password')));
</code></pre></div>
<table class="table table-bordered"><tr>
<th>package</th>
<td><a href="../packages/ActiveRecord.html">ActiveRecord</a></td>
</tr></table>
<h3>
<i class="icon-custom icon-method"></i> Methods</h3>
<a id="method___construct"></a><div class="element clickable method public method___construct" data-toggle="collapse" data-target=".method___construct .collapse">
<h2>Constructs a {@link Serialization} object.</h2>
<pre>__construct(\ActiveRecord\Model $model, array $options) : <a href="../classes/ActiveRecord.Serialization.html">\ActiveRecord\Serialization</a></pre>
<div class="labels"><span class="label">Inherited</span></div>
<div class="row collapse"><div class="detail-description">
<div class="long_description"></div>
<table class="table table-bordered">
<tr>
<th>inherited_from</th>
<td>\ActiveRecord\Serialization::__construct()</td>
</tr>
<tr>
<th>inherited_from</th>
<td>\ActiveRecord\ArraySerializer::__construct()</td>
</tr>
</table>
<h3>Parameters</h3>
<div class="subelement argument">
<h4>$model</h4>
<code><a href="../classes/ActiveRecord.Model.html">\ActiveRecord\Model</a></code><p>The model to serialize</p></div>
<div class="subelement argument">
<h4>$options</h4>
<code>array</code><p>&$options Options for serialization</p>
</div>
<h3>Returns</h3>
<div class="subelement response"><code><a href="../classes/ActiveRecord.Serialization.html">\ActiveRecord\Serialization</a></code></div>
</div></div>
</div>
<a id="method___toString"></a><div class="element clickable method public method___toString" data-toggle="collapse" data-target=".method___toString .collapse">
<h2>Returns the serialized object as a string.</h2>
<pre>__toString() : string</pre>
<div class="labels"><span class="label">Inherited</span></div>
<div class="row collapse"><div class="detail-description">
<div class="long_description"></div>
<table class="table table-bordered">
<tr>
<th>see</th>
<td><a href="">\ActiveRecord\to_s</a></td>
</tr>
<tr>
<th>inherited_from</th>
<td>\ActiveRecord\Serialization::__toString()</td>
</tr>
<tr>
<th>inherited_from</th>
<td>\ActiveRecord\ArraySerializer::__toString()</td>
</tr>
</table>
<h3>Returns</h3>
<div class="subelement response"><code>string</code></div>
</div></div>
</div>
<a id="method_to_a"></a><div class="element clickable method public method_to_a" data-toggle="collapse" data-target=".method_to_a .collapse">
<h2>Returns the attributes array.</h2>
<pre>to_a() : array</pre>
<div class="labels"><span class="label">Inherited</span></div>
<div class="row collapse"><div class="detail-description">
<div class="long_description"></div>
<table class="table table-bordered">
<tr>
<th>inherited_from</th>
<td>\ActiveRecord\Serialization::to_a()</td>
</tr>
<tr>
<th>inherited_from</th>
<td>\ActiveRecord\ArraySerializer::to_a()</td>
</tr>
</table>
<h3>Returns</h3>
<div class="subelement response"><code>array</code></div>
</div></div>
</div>
<a id="method_to_s"></a><div class="element clickable method public method_to_s" data-toggle="collapse" data-target=".method_to_s .collapse">
<h2>Performs the serialization.</h2>
<pre>to_s() : string</pre>
<div class="labels"></div>
<div class="row collapse"><div class="detail-description">
<div class="long_description"></div>
<h3>Returns</h3>
<div class="subelement response"><code>string</code></div>
</div></div>
</div>
<a id="method_options_to_a"></a><div class="element clickable method protected method_options_to_a" data-toggle="collapse" data-target=".method_options_to_a .collapse">
<h2>options_to_a()
        </h2>
<pre>options_to_a($key) </pre>
<div class="labels"><span class="label">Inherited</span></div>
<div class="row collapse"><div class="detail-description">
<div class="long_description"></div>
<table class="table table-bordered">
<tr>
<th>inherited_from</th>
<td>\ActiveRecord\Serialization::options_to_a()</td>
</tr>
<tr>
<th>inherited_from</th>
<td>\ActiveRecord\ArraySerializer::options_to_a()</td>
</tr>
</table>
<h3>Parameters</h3>
<div class="subelement argument"><h4>$key</h4></div>
</div></div>
</div>
<a id="method_check_except"></a><div class="element clickable method private method_check_except" data-toggle="collapse" data-target=".method_check_except .collapse">
<h2>check_except()
        </h2>
<pre>check_except() </pre>
<div class="labels"><span class="label">Inherited</span></div>
<div class="row collapse"><div class="detail-description">
<div class="long_description"></div>
<table class="table table-bordered">
<tr>
<th>inherited_from</th>
<td>\ActiveRecord\Serialization::check_except()</td>
</tr>
<tr>
<th>inherited_from</th>
<td>\ActiveRecord\ArraySerializer::check_except()</td>
</tr>
</table>
</div></div>
</div>
<a id="method_check_include"></a><div class="element clickable method private method_check_include" data-toggle="collapse" data-target=".method_check_include .collapse">
<h2>check_include()
        </h2>
<pre>check_include() </pre>
<div class="labels"><span class="label">Inherited</span></div>
<div class="row collapse"><div class="detail-description">
<div class="long_description"></div>
<table class="table table-bordered">
<tr>
<th>inherited_from</th>
<td>\ActiveRecord\Serialization::check_include()</td>
</tr>
<tr>
<th>inherited_from</th>
<td>\ActiveRecord\ArraySerializer::check_include()</td>
</tr>
</table>
</div></div>
</div>
<a id="method_check_methods"></a><div class="element clickable method private method_check_methods" data-toggle="collapse" data-target=".method_check_methods .collapse">
<h2>check_methods()
        </h2>
<pre>check_methods() </pre>
<div class="labels"><span class="label">Inherited</span></div>
<div class="row collapse"><div class="detail-description">
<div class="long_description"></div>
<table class="table table-bordered">
<tr>
<th>inherited_from</th>
<td>\ActiveRecord\Serialization::check_methods()</td>
</tr>
<tr>
<th>inherited_from</th>
<td>\ActiveRecord\ArraySerializer::check_methods()</td>
</tr>
</table>
</div></div>
</div>
<a id="method_check_only"></a><div class="element clickable method private method_check_only" data-toggle="collapse" data-target=".method_check_only .collapse">
<h2>check_only()
        </h2>
<pre>check_only() </pre>
<div class="labels"><span class="label">Inherited</span></div>
<div class="row collapse"><div class="detail-description">
<div class="long_description"></div>
<table class="table table-bordered">
<tr>
<th>inherited_from</th>
<td>\ActiveRecord\Serialization::check_only()</td>
</tr>
<tr>
<th>inherited_from</th>
<td>\ActiveRecord\ArraySerializer::check_only()</td>
</tr>
</table>
</div></div>
</div>
<a id="method_check_only_method"></a><div class="element clickable method private method_check_only_method" data-toggle="collapse" data-target=".method_check_only_method .collapse">
<h2>check_only_method()
        </h2>
<pre>check_only_method() </pre>
<div class="labels"><span class="label">Inherited</span></div>
<div class="row collapse"><div class="detail-description">
<div class="long_description"></div>
<table class="table table-bordered">
<tr>
<th>inherited_from</th>
<td>\ActiveRecord\Serialization::check_only_method()</td>
</tr>
<tr>
<th>inherited_from</th>
<td>\ActiveRecord\ArraySerializer::check_only_method()</td>
</tr>
</table>
</div></div>
</div>
<a id="method_parse_options"></a><div class="element clickable method private method_parse_options" data-toggle="collapse" data-target=".method_parse_options .collapse">
<h2>parse_options()
        </h2>
<pre>parse_options() </pre>
<div class="labels"><span class="label">Inherited</span></div>
<div class="row collapse"><div class="detail-description">
<div class="long_description"></div>
<table class="table table-bordered">
<tr>
<th>inherited_from</th>
<td>\ActiveRecord\Serialization::parse_options()</td>
</tr>
<tr>
<th>inherited_from</th>
<td>\ActiveRecord\ArraySerializer::parse_options()</td>
</tr>
</table>
</div></div>
</div>
<h3>
<i class="icon-custom icon-property"></i> Properties</h3>
<a id="property_DATETIME_FORMAT"> </a><div class="element clickable property public property_DATETIME_FORMAT" data-toggle="collapse" data-target=".property_DATETIME_FORMAT .collapse">
<h2></h2>
<pre>$DATETIME_FORMAT </pre>
<div class="labels"><span class="label">Inherited</span></div>
<div class="row collapse"><div class="detail-description">
<div class="long_description"></div>
<table class="table table-bordered">
<tr>
<th>see</th>
<td><a href="protected.core.libs.active_record.lib.DateTime.html#%5CActiveRecord%5CDateTime">\ActiveRecord\DateTime</a></td>
</tr>
<tr>
<th>inherited_from</th>
<td>\ActiveRecord\Serialization::$$DATETIME_FORMAT</td>
</tr>
<tr>
<th>inherited_from</th>
<td>\ActiveRecord\ArraySerializer::$$DATETIME_FORMAT</td>
</tr>
</table>
</div></div>
</div>
<a id="property_include_root"> </a><div class="element clickable property public property_include_root" data-toggle="collapse" data-target=".property_include_root .collapse">
<h2></h2>
<pre>$include_root </pre>
<div class="labels"></div>
<div class="row collapse"><div class="detail-description"><div class="long_description"></div></div></div>
</div>
<a id="property_attributes"> </a><div class="element clickable property protected property_attributes" data-toggle="collapse" data-target=".property_attributes .collapse">
<h2></h2>
<pre>$attributes </pre>
<div class="labels"><span class="label">Inherited</span></div>
<div class="row collapse"><div class="detail-description">
<div class="long_description"></div>
<table class="table table-bordered">
<tr>
<th>inherited_from</th>
<td>\ActiveRecord\Serialization::$$attributes</td>
</tr>
<tr>
<th>inherited_from</th>
<td>\ActiveRecord\ArraySerializer::$$attributes</td>
</tr>
</table>
</div></div>
</div>
<a id="property_includes_with_class_name_element"> </a><div class="element clickable property protected property_includes_with_class_name_element" data-toggle="collapse" data-target=".property_includes_with_class_name_element .collapse">
<h2></h2>
<pre>$includes_with_class_name_element : boolean</pre>
<div class="labels"><span class="label">Inherited</span></div>
<div class="row collapse"><div class="detail-description">
<div class="long_description"><p>Setting this to true will produce the following attributes array when
the include option was used:</p>

<pre><code>$user = array('id' => 1, 'name' => 'Tito',
  'permissions' => array(
    'permission' => array(
      array('id' => 100, 'name' => 'admin'),
      array('id' => 101, 'name' => 'normal')
    )
  )
);
</code></pre>

<p>Setting to false will produce this:</p>

<pre><code>$user = array('id' => 1, 'name' => 'Tito',
  'permissions' => array(
    array('id' => 100, 'name' => 'admin'),
    array('id' => 101, 'name' => 'normal')
  )
);
</code></pre></div>
<table class="table table-bordered">
<tr>
<th>inherited_from</th>
<td>\ActiveRecord\Serialization::$$includes_with_class_name_element</td>
</tr>
<tr>
<th>inherited_from</th>
<td>\ActiveRecord\ArraySerializer::$$includes_with_class_name_element</td>
</tr>
</table>
</div></div>
</div>
<a id="property_model"> </a><div class="element clickable property protected property_model" data-toggle="collapse" data-target=".property_model .collapse">
<h2></h2>
<pre>$model </pre>
<div class="labels"><span class="label">Inherited</span></div>
<div class="row collapse"><div class="detail-description">
<div class="long_description"></div>
<table class="table table-bordered">
<tr>
<th>inherited_from</th>
<td>\ActiveRecord\Serialization::$$model</td>
</tr>
<tr>
<th>inherited_from</th>
<td>\ActiveRecord\ArraySerializer::$$model</td>
</tr>
</table>
</div></div>
</div>
<a id="property_options"> </a><div class="element clickable property protected property_options" data-toggle="collapse" data-target=".property_options .collapse">
<h2></h2>
<pre>$options </pre>
<div class="labels"><span class="label">Inherited</span></div>
<div class="row collapse"><div class="detail-description">
<div class="long_description"></div>
<table class="table table-bordered">
<tr>
<th>inherited_from</th>
<td>\ActiveRecord\Serialization::$$options</td>
</tr>
<tr>
<th>inherited_from</th>
<td>\ActiveRecord\ArraySerializer::$$options</td>
</tr>
</table>
</div></div>
</div>
</div>
</div>
</div>
</div>
<div class="row"><footer class="span12">
            Template is built using <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap 2</a> and icons provided by <a href="http://glyphicons.com/">Glyphicons</a>.<br>
            Documentation is powered by <a href="http://www.phpdoc.org/">phpDocumentor 2.0.0a12</a> and<br>
            generated on 2013-06-08T13:56:19-04:30.<br></footer></div>
</div>
</body>
</html>
